//
//  KVNHomeHotSource.m
//  Test1
//
//  Created by KelvinYeung on 15/7/18.
//  Copyright (c) 2015年 KelvinYeung. All rights reserved.
//

#import "KVNHomeHotSource.h"
#import <QuartzCore/QuartzCore.h>

#define KVN_HOME_HOT_SUOURCE_VIEW_HOT_SALE 0
#define KVN_HOME_HOT_SUOURCE_VIEW_HOT_RENT 1
#define KVN_HOME_HOT_SUOURCE_VIEW_HOT_SCROLLVIEW 2
#define TABLE_VIEW_CELL_HEIGHT 90.0
@interface KVNHomeHotSource()


//tab页
@property CALayer *indicatorLayer ;
@property CABasicAnimation *indicatorAnimation;//指示器
@property NSInteger currentPage; //当前页
@property UIScrollView *scrollView;

//热门团购
@property UIButton *hotSaleBtn;
@property UITableView *hotSaleTableView;
@property int hotSaleDataCurrentPage;
@property NSMutableArray *hotSaleData;
@property UIView * hotSaleTableViewFooterView;
@property UILabel * hotSaleTableViewFooterViewLabel;
@property UIActivityIndicatorView *hotSaleTableViewFooterViewIndicator;
@property BOOL isHotSaleLoading;

//热门团租
@property UIButton *hotRentBtn;
@property UITableView *hotRentTableView;
@property int hotRentDataCurrentPage;
@property NSMutableArray *hotRentData;
@property UIView * hotRentTableViewFooterView;
@property UILabel * hotRentTableViewFooterViewLabel;
@property UIActivityIndicatorView *hotRentTableViewFooterViewIndicator;
@property BOOL isHotRentLoading;


@property float tabViewMaxHeight;

@end

@implementation KVNHomeHotSource
@synthesize indicatorLayer;
@synthesize indicatorAnimation;
@synthesize currentPage;
@synthesize scrollView;
@synthesize hotRentList;
@synthesize hotSaleList;
@synthesize hotSaleTableView;
@synthesize hotRentTableView;
@synthesize hotSaleBtn;
@synthesize hotRentBtn;
@synthesize tabViewMaxHeight;


- (instancetype) init{
    self = [super init];
    [self initSubViews];
    return self;
}


- (instancetype) initWithFrame:(CGRect)aRect
{
    self = [super initWithFrame:aRect];
    //[self initSubViews];
    return self;
}

- (void) initSubViews
{
    //初始化最大高度
    tabViewMaxHeight =  TABLE_VIEW_CELL_HEIGHT * 4.0;//最多显示6个cell
    float viewWidth  = [[UIScreen mainScreen] applicationFrame].size.width;
    
    
    //热门团购按钮
    hotSaleBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, viewWidth*0.5, 46)];
    [hotSaleBtn setTitle:@"热门团购" forState:UIControlStateNormal];
    [hotSaleBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    hotSaleBtn.backgroundColor = [UIColor whiteColor];
    hotSaleBtn.tag = 0;
    [hotSaleBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    //热门团租按钮
    hotRentBtn = [[UIButton alloc] initWithFrame:CGRectMake(viewWidth*0.5, 0, viewWidth*0.5, 46)];
    [hotRentBtn setTitle:@"热门团租" forState:UIControlStateNormal];
    [hotRentBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    //hotRentBtn.backgroundColor = [UIColor whiteColor];
    hotRentBtn.tag = 1;
    [hotRentBtn addTarget:self action:@selector(buttonClick:) forControlEvents:
     UIControlEventTouchUpInside];
    hotRentBtn.backgroundColor = [UIColor whiteColor];
    
    [self addSubview:hotSaleBtn];
    [self addSubview:hotRentBtn];
    
    
    
    //分页指示器
    indicatorLayer = [[CALayer alloc]init];
    indicatorLayer.backgroundColor = [[UIColor colorWithRed:1 green:0 blue:0 alpha:0.8] CGColor];
    indicatorLayer.frame = CGRectMake(viewWidth*0.125, 43, viewWidth*0.25, 3);
    [self.layer addSublayer:indicatorLayer]; // 增加到UIView的layer上面
    
    indicatorAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
    indicatorAnimation.fromValue = [NSValue valueWithCGPoint:indicatorLayer.position];
    //indicatorAnimation.duration = 1;
    CGPoint toPoint = indicatorLayer.position;
    toPoint.x += viewWidth*0.5;
    indicatorAnimation.toValue = [NSValue valueWithCGPoint:toPoint];
    indicatorAnimation.removedOnCompletion = NO;
    indicatorAnimation.delegate = self;
    indicatorAnimation.fillMode = kCAFillModeBoth;
    
    
    //scrollView
    scrollView =  [[UIScrollView alloc] init];
    scrollView.tag = KVN_HOME_HOT_SUOURCE_VIEW_HOT_SCROLLVIEW;
    scrollView.pagingEnabled = YES;
    //scrollView.backgroundColor = [UIColor redColor];
    scrollView.alwaysBounceVertical = NO;
    scrollView.delegate = self;
    scrollView.frame = CGRectMake(0, 46, viewWidth, 200);
    //scrollView.backgroundColor = [UIColor purpleColor];
    [self addSubview:scrollView];
    
    
    //热门团购
    hotSaleTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, viewWidth, 0) style:UITableViewStylePlain];
    hotSaleTableView.tag = KVN_HOME_HOT_SUOURCE_VIEW_HOT_SALE;
    hotSaleTableView.delegate = self;
    hotSaleTableView.dataSource = self;
    hotSaleTableView.rowHeight = 100;
    hotSaleTableView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
    [scrollView addSubview:hotSaleTableView];
    
    _hotSaleTableViewFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 30)];
    _hotSaleTableViewFooterViewLabel = [[UILabel alloc] init];
    _hotSaleTableViewFooterViewIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    _hotSaleTableViewFooterViewLabel.text = @"上拉加载更多数据";
    _hotSaleTableViewFooterViewLabel.textColor = [UIColor grayColor];
    _hotSaleTableViewFooterViewLabel.font = [UIFont systemFontOfSize:12];
    _hotSaleTableViewFooterViewIndicator.hidesWhenStopped = YES;
    _hotSaleTableViewFooterViewIndicator.hidden = YES;
    [_hotSaleTableViewFooterView addSubview:_hotSaleTableViewFooterViewLabel];
    [_hotSaleTableViewFooterView addSubview:_hotSaleTableViewFooterViewIndicator];
    [hotSaleTableView setTableFooterView:_hotSaleTableViewFooterView];
    
    _hotSaleTableViewFooterViewLabel.translatesAutoresizingMaskIntoConstraints = NO;
    [_hotSaleTableViewFooterView addConstraint:[NSLayoutConstraint constraintWithItem:_hotSaleTableViewFooterViewLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:_hotSaleTableViewFooterView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    [_hotSaleTableViewFooterView addConstraint:[NSLayoutConstraint constraintWithItem:_hotSaleTableViewFooterViewLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:_hotSaleTableViewFooterView attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
    
    
    _hotSaleTableViewFooterViewIndicator.translatesAutoresizingMaskIntoConstraints = NO;
    [_hotSaleTableViewFooterView addConstraint:[NSLayoutConstraint constraintWithItem:_hotSaleTableViewFooterViewIndicator attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:_hotSaleTableViewFooterView attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
    [_hotSaleTableViewFooterView addConstraint:[NSLayoutConstraint constraintWithItem:_hotSaleTableViewFooterViewIndicator attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:_hotSaleTableViewFooterViewLabel attribute:NSLayoutAttributeLeft multiplier:1 constant:0]];
    
    
    

    
    //热门团租
    hotRentTableView = [[UITableView alloc] initWithFrame:CGRectMake(viewWidth, 0, viewWidth,0) style:UITableViewStylePlain];
    hotRentTableView.tag = KVN_HOME_HOT_SUOURCE_VIEW_HOT_RENT;
    hotRentTableView.delegate = self;
    hotRentTableView.dataSource = self;
    hotRentTableView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
    hotRentTableView.rowHeight = 100;
    [scrollView addSubview:hotRentTableView];
    
    
    
    
    
    scrollView.contentSize = CGSizeMake(viewWidth*2, 100);
    self.backgroundColor = [UIColor yellowColor];
}


- (void) buttonClick:(id) sender{
   // NSLog(@"ButtonClick.....");
    NSInteger tag = ((UIButton *) sender).tag;
    if(tag == 0 && currentPage != 0){
        currentPage = 0;
        [indicatorLayer addAnimation:indicatorAnimation forKey:@"indicatorLayerMove"];
        id tmpPoint = indicatorAnimation.fromValue;
        indicatorAnimation.fromValue = indicatorAnimation.toValue;
        indicatorAnimation.toValue = tmpPoint;
        [scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
        
    }else if(tag == 1 && currentPage != 1) {
        currentPage = 1;
        [indicatorLayer addAnimation:indicatorAnimation forKey:@"indicatorLayerMove"];
        id tmpPoint = indicatorAnimation.fromValue;
        indicatorAnimation.fromValue = indicatorAnimation.toValue;
        indicatorAnimation.toValue = tmpPoint;
        [scrollView setContentOffset:CGPointMake(self.frame.size.width, 0) animated:YES];
    }
    

}

- (void) setHotRentList:(NSMutableDictionary *)aHotRentList{
    

    
    float  height =hotRentTableView.rowHeight * [[aHotRentList objectForKey:@"data"] count];
    CGRect rect = hotRentTableView.frame;
    [hotRentTableView setFrame:CGRectMake(rect.origin.x,rect.origin.y,rect.size.width,height>(tabViewMaxHeight-46)?(tabViewMaxHeight-46-40):(height-40))];//40为tabbar高度

    [self resetSizeByHeight:height];
    
    [hotRentTableView reloadData] ;
   }

- (void) setHotSaleList:(NSMutableDictionary *)aHotSaleList{
    
    float  height =hotSaleTableView.rowHeight * [[aHotSaleList objectForKey:@"data"] count];
    CGRect rect = hotSaleTableView.frame;
    hotSaleTableView.frame = CGRectMake(rect.origin.x,rect.origin.y,rect.size.width,height>(tabViewMaxHeight-46)?(tabViewMaxHeight-46-40):(height-40));
    
    [self resetSizeByHeight:height];
    
    NSLog(@"heigt is :: %f",height);
    [hotSaleTableView reloadData] ;
    
    
}

//热门团租 、热门团购，以高度最大的为高度共同高度
- (void) resetSizeByHeight:(float) height{
    
    float tmpHeight = hotSaleTableView.frame.size.height >hotRentTableView.frame.size.height?hotSaleTableView.frame.size.height:hotRentTableView.frame.size.height ;
    
    if (height + 46 >tabViewMaxHeight){
        tmpHeight = tabViewMaxHeight;
    }else if(height > tmpHeight){
        tmpHeight = height;
    }
    
    [hotSaleTableView setFrame:CGRectMake(hotSaleTableView.frame.origin.x, hotSaleTableView.frame.origin.y, hotSaleTableView.frame.size.width, tmpHeight)];
    
    [hotRentTableView setFrame:CGRectMake(hotRentTableView.frame.origin.x, hotRentTableView.frame.origin.y, hotRentTableView.frame.size.width, tmpHeight)];

    [self setFrame:CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, tmpHeight + 46+50)];
    [scrollView setFrame:CGRectMake(self.scrollView.frame.origin.x, self.scrollView.frame.origin.y, self.scrollView.frame.size.width, tmpHeight)];
  
    //通知父视图变更size
    [[NSNotificationCenter defaultCenter] postNotificationName:@"KVN_HOME_VIEW_WILL_LAYOUT" object:Nil];

    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    [super drawRect:rect];

    
}
*/

#pragma mark - 滚动停止后改变currentPage的值
- (void) scrollViewDidEndDecelerating:(UIScrollView *)aScrollView{

    if (aScrollView.tag == KVN_HOME_HOT_SUOURCE_VIEW_HOT_SCROLLVIEW) {
        int index = (self.scrollView.contentOffset.x
                     / self.scrollView.frame.size.width);
        
        if(currentPage != index && index==0){
            currentPage = 0;
            [indicatorLayer addAnimation:indicatorAnimation forKey:@"indicatorLayerMove"];
            id tmpPoint = indicatorAnimation.fromValue;
            indicatorAnimation.fromValue = indicatorAnimation.toValue;
            indicatorAnimation.toValue = tmpPoint;
            
        }else if(currentPage != 1 && index == 1) {
            currentPage = 1;
            [indicatorLayer addAnimation:indicatorAnimation forKey:@"indicatorLayerMove"];
            id tmpPoint = indicatorAnimation.fromValue;
            indicatorAnimation.fromValue = indicatorAnimation.toValue;
            indicatorAnimation.toValue = tmpPoint;
        }
    }
}



#pragma mark -tableView的代理方法

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView.tag == KVN_HOME_HOT_SUOURCE_VIEW_HOT_SALE) {
        //通知父视图打开热门房子资料
        NSLog(@"houseID:::,%@",[[_hotSaleData objectAtIndex:indexPath.row] valueForKey:@"houseId"]);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"KVN_HOME_VIEW_WILL_SHOW_HOT_SRC_DETAIL" object:[[_hotSaleData objectAtIndex:indexPath.row] valueForKey:@"houseId"]];
    }

    
    if (tableView.tag == KVN_HOME_HOT_SUOURCE_VIEW_HOT_RENT) {
        //通知父视图打开热门房子资料
        [[NSNotificationCenter defaultCenter] postNotificationName:@"KVN_HOME_VIEW_WILL_SHOW_HOT_SRC_DETAIL" object:[[_hotRentData objectAtIndex:indexPath.row] valueForKey:@"houseId"]];
    }
   

}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    switch (tableView.tag) {
        case KVN_HOME_HOT_SUOURCE_VIEW_HOT_SALE:
            return _hotSaleData.count;
            break;
        case KVN_HOME_HOT_SUOURCE_VIEW_HOT_RENT:
            return _hotRentData.count;
            break;
        default:
            return 0;
            break;
    }

    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (tableView.tag == KVN_HOME_HOT_SUOURCE_VIEW_HOT_SALE) {
        KVNHouseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: @"HOME_HOT_SALE_CELL"];
        
        if (!cell) {
            cell = [[KVNHouseTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HOME_HOT_SALE_CELL"];
            cell.showsReorderControl = YES;
            [cell.indicatorImageView setImage:[UIImage imageNamed:@"index_icon_bulk"]];
        }
        
        cell.titleView.text =[[_hotSaleData objectAtIndex:indexPath.row] valueForKey:@"houseName"];
        cell.valueView1.text = [[_hotSaleData objectAtIndex:indexPath.row] valueForKey:@"address"];
        cell.valueView2.text = [[_hotSaleData objectAtIndex:indexPath.row] valueForKey:@"perferentialContent"];
        
        //设置价格
        NSString *priceString = [NSString stringWithFormat:@"%@元/m2", [[_hotSaleData objectAtIndex:indexPath.row] valueForKey:@"price"]];
        NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc]initWithString:priceString];
        [attrString addAttribute:(id)kCTSuperscriptAttributeName value:@1 range:NSMakeRange(priceString.length - 1, 1)];
        [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(priceString.length - 1, 1)];
        [cell.valueView3 setAttributedText:attrString];
        
        [cell.defaultImageView setImageFromURL:[NSURL URLWithString:[[_hotSaleData objectAtIndex:indexPath.row] valueForKey:@"defaultImage"]] placeHolderImage:[UIImage imageNamed:@"cell_loading"]];
        
        //计算剩余天数
        NSTimeInterval preferentialEndTime =[[[_hotSaleData objectAtIndex:indexPath.row] valueForKey:@"preferentialEndtime"] doubleValue];
        
        NSDate *preferentialDate = [NSDate dateWithTimeIntervalSince1970:preferentialEndTime];
        
        NSTimeInterval timeInterval =[preferentialDate timeIntervalSinceNow];
        //天数
        if(timeInterval<0){
            [cell.valueView4 setText:@"剩余0天"];
        }else{
            int days = ceil(timeInterval/(24*60*60));
            [cell.valueView4 setText:[NSString stringWithFormat:@"剩余%d天",days]];
        }
        

        
        return cell;
    }
    
    if (tableView.tag == KVN_HOME_HOT_SUOURCE_VIEW_HOT_RENT) {
        KVNHouseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: @"HOME_HOT_RENT_CELL"];
        
        if (!cell) {
            cell = [[KVNHouseTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HOME_HOT_RENT_CELL"];
            cell.showsReorderControl = YES;
           // [cell.indicatorImageView setImage:[UIImage imageNamed:@"index_icon_specialShop"]];
        }
       
        
        
        cell.titleView.text =[[_hotRentData objectAtIndex:indexPath.row] valueForKey:@"houseName"];
        cell.valueView1.text = [[_hotRentData objectAtIndex:indexPath.row] valueForKey:@"address"];
        cell.valueView2.text = [[_hotRentData objectAtIndex:indexPath.row] valueForKey:@"perferentialContent"];
        
        //设置价格
        NSString *priceString = [NSString stringWithFormat:@"%@元/m2", [[_hotRentData objectAtIndex:indexPath.row] valueForKey:@"price"]];
        NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc]initWithString:priceString];
        [attrString addAttribute:(id)kCTSuperscriptAttributeName value:@1 range:NSMakeRange(priceString.length - 1, 1)];
        [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(priceString.length - 1, 1)];
        [cell.valueView3 setAttributedText:attrString];
        
        [cell.defaultImageView setImageFromURL:[NSURL URLWithString:[[_hotRentData objectAtIndex:indexPath.row] valueForKey:@"defaultImage"]] placeHolderImage:[UIImage imageNamed:@"cell_loading"]];
        
        //计算剩余天数
        /*
        NSTimeInterval preferentialEndTime =[[[_hotRentData objectAtIndex:indexPath.row] valueForKey:@"preferentialEndtime"] doubleValue];
        
        NSDate *preferentialDate = [NSDate dateWithTimeIntervalSince1970:preferentialEndTime];
        
        NSTimeInterval timeInterval =[preferentialDate timeIntervalSinceNow];
        //天数
        if(timeInterval<0){
            [cell.valueView4 setText:@"剩余0天"];
        }else{
            int days = ceil(timeInterval/(24*60*60));
            [cell.valueView4 setText:[NSString stringWithFormat:@"剩余%d天",days]];
        }
         */
        return cell;
    }
    
    
    return nil;
}

//重新设置单元格高度；
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return TABLE_VIEW_CELL_HEIGHT;
}



#pragma mark - 数据请求
- (void)reloadData{
    [self queryData];
}

- (void) queryData{
    NSLog(@"reloadData.....");
    //团购
    [ApplicationDelegate.httpRequestEngine homeHotListWithType:1 pageNumber:_hotSaleDataCurrentPage + 1 pageSize:2 completionHandler:^(MKNetworkOperation *operation) {
        
        if(_hotSaleData == nil){
            _hotSaleData = [[NSMutableArray alloc] init];
        }
        
        NSArray *data = [[operation responseJSON] valueForKey:@"data"];
        if ([data isEqual:[NSNull null]]) {
            _hotSaleTableViewFooterViewLabel.text = @"没有更多数据";
        }else{
            NSLog(@"hello....");
            _hotSaleDataCurrentPage ++;
            [_hotSaleData addObjectsFromArray:data];
            [hotSaleTableView reloadData];
            [self resetSizeByHeight:100*_hotSaleData.count];
            _hotSaleTableViewFooterViewLabel.text = @"上拉加载更多数据";
        }
        _isHotSaleLoading = NO;
         [_hotSaleTableViewFooterViewIndicator stopAnimating];
    } errorHandler:^(NSError *error) {
        NSLog(@"ERROR:REQUEST HOME HOT SALE DATA:%@ ",error.localizedDescription);
    }];
    
    //团租
    [ApplicationDelegate.httpRequestEngine homeHotListWithType:2 pageNumber:_hotRentDataCurrentPage+1 pageSize:2 completionHandler:^(MKNetworkOperation *operation) {
        if(_hotRentData == nil){
            _hotRentData = [[NSMutableArray alloc] init];
        }
        
        NSArray *data = [[operation responseJSON] valueForKey:@"data"];
        if ([data isEqual:[NSNull null]]) {
            _hotRentTableViewFooterViewLabel.text = @"没有更多数据";
        }else{
            _hotRentDataCurrentPage ++;
            [_hotRentData addObjectsFromArray:data];
            [hotRentTableView reloadData];
            [self resetSizeByHeight:100*_hotRentData.count];
            _hotRentTableViewFooterViewLabel.text = @"上拉加载更多数据";
        }
        
        _isHotRentLoading = NO;
        [_hotRentTableViewFooterViewIndicator stopAnimating];
        
    } errorHandler:^(NSError *error) {
        NSLog(@"ERROR:REQUEST HOME HOT RENT DATA:%@ ",error.localizedDescription);
    }];
}


#pragma mark -scrollView的代理方法
//上拉加载更多数据
-(void)scrollViewDidScroll:(UIScrollView *)aScrollView{
    
    if (aScrollView.tag == KVN_HOME_HOT_SUOURCE_VIEW_HOT_SALE) {
        
        //假设偏移表格高度r20%进行刷新
        if (_isHotSaleLoading == NO) {//判断是否处于刷新状态，刷新中不执行
            //取内容高度
            //  如果内容高度大于UItableView高度，取UItableView高度
            //  如果内容高度小于UITableView高度, 取内容高度
            float height = hotSaleTableView.contentSize.height>hotSaleTableView.bounds.size.height?hotSaleTableView.bounds.size.height:hotSaleTableView.contentSize.height;
            
            if ((height - hotSaleTableView.contentSize.height + hotSaleTableView.contentOffset.y)/height > 0.2) {
                //调用上拉刷新方法
                
                [self queryData];
                [_hotSaleTableViewFooterViewIndicator startAnimating];
                _hotSaleTableViewFooterViewLabel.text = @"数据加载中...";
                _isHotSaleLoading = YES;
            }
            
            if (- hotSaleTableView.contentOffset.y /hotSaleTableView.bounds.size.height > 0.2) {
                //调用下拉刷新方法
                
                
            }
            
        }

    }else if (aScrollView.tag == KVN_HOME_HOT_SUOURCE_VIEW_HOT_RENT) {
        
        //假设偏移表格高度r20%进行刷新
        if (_isHotRentLoading == NO) {//判断是否处于刷新状态，刷新中不执行
            //取内容高度
            //  如果内容高度大于UItableView高度，取UItableView高度
            //  如果内容高度小于UITableView高度, 取内容高度
            float height = hotRentTableView.contentSize.height>hotRentTableView.bounds.size.height?hotRentTableView.bounds.size.height:hotRentTableView.contentSize.height;
            
            if ((height - hotRentTableView.contentSize.height + hotRentTableView.contentOffset.y)/height > 0.2) {
                //调用上拉刷新方法
                
                [self queryData];
                [_hotRentTableViewFooterViewIndicator startAnimating];
                _hotRentTableViewFooterViewLabel.text = @"数据加载中...";
                _isHotRentLoading = YES;
            }
            
            if (- hotRentTableView.contentOffset.y /hotRentTableView.bounds.size.height > 0.2) {
                //调用下拉刷新方法
                
                
            }
            
        }
        
    }
    
    
}




@end
